//HOMEWORK
//
//ATM (class)
//
//- name
//- costumers
//
//You need to be able to login with an account id and password
//You need to be able to store multiple accounts
//After any transaction you are automatically logged out
//
//Costumer (class)
//
//- First name
//- Last name
//- ID
//
//The costumer has just one account
//
//Account
//
//- ID
//- Balance
//- Password
//
//You need to be able to do a withdrawal, a deposit, check balance
//
//
//
//Create a HTML page with text page and Imput field. Do two divs; one for text another with input text and button. 
//
//Login-Menu-Seccio

//var validation = function Validation (){
//
//    var userValidation = document.getElementById("user");
//    var passwordValidation = document.getElementById("password");
//
//    if (userValidation == userArgument && passwordValidation == passwordArgument) {
//

//
//}





//MENU


var atm = function Atm (location){
    
    var atmId = 0;
    
    ++atmId;
    
        this.atmId = atmId;
    
    var atmAdress = location;
    
        this.atmAdress = atmAdress;
    
    var atmCostumers = new Array ();
        
        this.atmCostumers = atmCostumers;
    
    
    
// COSTUMER  



     var costumer = function Costumer (firstName, lastName) {
        
        var costumerObject = {
            "Name": this.costumerName,
            "Identification": this.userId,
            "Password": this.userPass,
            "Accounts": this.costumerAccounts
        };
        
        
        var costumerName = firstName + " " + lastName;
            
            this.costumerName = costumerName;
            
        
        var userId;    
          
        var userIdGenerator = function UserIdGenerator (){

                //is it really necessary to declare tha variable for the function?? Looks stupid...

                userId = Math.floor(Math.random()*900000000) + 100000000;
                return userId;
            }
        new userIdGenerator() ;  
        this.userId = userId;           
           
                   
        var userPass; 
        
        var userPassGenerator = function UserPassGenerator (){
            
            userPass = Math.floor(Math.random()*9000) + 1000;
            return userPass;
            
            
        }
        
        new userPassGenerator ();
        this.userPass = userPass;   
        
            
       atmCostumers = atmCostumers.push(costumerObject); 
            
        var costumerAccounts = new Array();
        
            this.costumerAccounts = costumerAccounts;
        
        
        
    //ACCOUNT
        
        
        
        var account = function Account (userId, initialAmount) {
        
    //        NEW ACCOUNT
           
           var accountId;

           var accountIdGenerator = function AccountIdGenerator (){
                accountId = Math.floor(Math.random()*900000000) + 100000000;
                return accountId;
            }
                this.accountId = accountId;

            costumerAccounts =  costumerAccounts.push(accountId);

            var currentBalance = initialAmount;

                this.currentBalance = currentBalance;
                
            console.debug("Thank you Mr. %s, your account number %n was created with an initial balance of %n euros. \nHave a nice day", this.costumerName, this.accountId, this.currentBalance);            
            
            
    //       NEW DEPOSIT
            
            
            this.deposit = function(depositAmount){

                currentBalance = currentBalance + depositAmount;
                return currentBalance; //is it necessary?
                console.debug("Now you are %n richer, bitch", depositAmount);
            };
            
            
            
    //       NEW WITHDRAWAL
            
            
            this.withdraw = function(withdrawAmount){

                currentBalance = currentBalance - withdrawAmount;
                return currentBalance;
                console.debug("Now you are %n more poor, bitch", withdrawAmount);
            };              
                
                

//       CHECK DEPOSIT
    
            this.currenBalance = function(){  
                console.log("Mr. %s, your total credit is %n", this.name, this.currentBalance );
            };
        }
    }
    
    this.costumer = costumer; //per poguer accedir a costumer desde fora!! En serio cal??? No seria millor ferla global??
}





var firstAtm = new atm ("Wallstreet 890, Manhattan, NY");


console.log(firstAtm.atmId);
console.log(firstAtm.atmAdress);
console.log(firstAtm.atmCostumers);


var sergi = new firstAtm.costumer ("Sergi", "Gómez");


console.log(sergi.costumerName);
console.log(sergi.userId);
console.log(sergi.userPass);
console.log(sergi.costumerAccounts);


console.log(firstAtm.atmCostumers);